package com.kfm.pm;

import java.sql.*;

public class PrepareCallDemo {


    public static void main(String[] args) throws SQLException {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }

        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/manager", "root", "");
        // JDBC中调用存储过程  CallableStatement
//        CallableStatement callableStatement = conn.prepareCall("{call cal_salary(?)}");
//        callableStatement.setInt(1, 7788);
//        ResultSet resultSet = callableStatement.executeQuery();
//        if (resultSet.next()) {
//            System.out.println(resultSet.getObject(1));
//        }
        CallableStatement callableStatement = conn.prepareCall("{call `sum`(?, ?, ?)}");
        callableStatement.setInt(1, 2);
        callableStatement.setInt(2, 4);
        // 注入 OUT类型的参数 registerOutParameter(, 类型)
        callableStatement.registerOutParameter(3, Types.INTEGER);
        callableStatement.execute();
        // getXXX(3)
        int sum = callableStatement.getInt(3);
        System.out.println(sum);
    }
}
